

<script type="text/javascript">
function editPhoto(obj, isShow){
	if(isShow){
		$('headerBox_<?php echo $this->subject()->getType()?>_<?php echo $this->subject()->getIdentity()?>').hide();
		$('boxEdit_<?php echo $this->subject()->getType()?>_<?php echo $this->subject()->getIdentity()?>').show();
		if($('aEdit_<?php echo $this->subject()->getType()?>_<?php echo $this->subject()->getIdentity()?>')) $('aEdit_<?php echo $this->subject()->getType()?>_<?php echo $this->subject()->getIdentity()?>').addClass('disableEdit');
	}else{
		$('headerBox_<?php echo $this->subject()->getType()?>_<?php echo $this->subject()->getIdentity()?>').show();
		$('boxEdit_<?php echo $this->subject()->getType()?>_<?php echo $this->subject()->getIdentity()?>').hide();
		if($('aEdit_<?php echo $this->subject()->getType()?>_<?php echo $this->subject()->getIdentity()?>')) $('aEdit_<?php echo $this->subject()->getType()?>_<?php echo $this->subject()->getIdentity()?>').removeClass('disableEdit');
	}
}
en4.core.runonce.add(function() {

	  var descEls = $$('.albums_viewmedia_info_caption');
	    if( descEls.length > 0 ) {
	      descEls[0].enableLinks();
	    }

	    TaggerChild = new Class({
	    	Extends: Tagger,
	  	  	options : {
			    // Local options
			    'title' : false,
			    'description' : false,
			    'transImage' : 'application/modules/Core/externals/images/trans.gif',
			    'existingTags' : [],
			    'tagListElement' : false,
			    'linkElement' : false,
			    'noTextTagHref' : true,
			    'guid' : false,
			    'enableCreate' : false,
			    'enableDelete' : false,
		
			    // Create
			    'createRequestOptions' : {
			      'url' : '',
			      'data' : {
			        'format' : 'json'
			      }
			    },
			    'deleteRequestOptions' : {
			      'url' : '',
			      'data' : {
			        'format' : 'json'
			      }
			    },
		
			    // Cropper options
			    'cropOptions' : {
			      'preset' : [10,10,58,58],
			      'min' : [48,48],
			      'max' : [128,128],
			      'handleSize' : 8,
			      'opacity' : .6,
			      'color' : '#7389AE',
			      'border' : 'externals/moolasso/crop.gif'
			    },
		
			    // Autosuggest options
			    'suggestProto' : 'local',
			    'suggestParam' : [
			      
			    ],
			    'suggestOptions' : {
			      'minLength': 0,
			      'maxChoices' : 100,
			      'delay' : 250,
			      'selectMode': 'pick',
			      //'autocompleteType': 'message',
			      'multiple': false,
			      'className': 'message-autosuggest',
			      'filterSubset' : true,
			      'tokenFormat' : 'object',
			      'tokenValueKey' : 'label',
			      'injectChoice': $empty,
			      'onPush' : $empty,
			      
			      'prefetchOnInit' : true,
			      'alwaysOpen' : true,
			      'ignoreKeys' : true
			    }
			},
	    	initialize: function(el, options) {
	    	    el = $(el);
	    	    if( el.get('tag') != 'img' ) {
	    	      this.image = el.getElement('img');
	    	    } else {
	    	      this.image = el;
	    	    }
	    	    this.element = el;
	    	    this.count = 0;   	    
	    	    this.setOptions(options);
	    	    //this.element.addEvent('')
		   	    this.options.existingTags.each(this.addTag.bind(this));		
	    	},
	  	  	onMove : function(coords) {
	  	  	   $sizeParent = $('innerLeftCol').getSize();
	  	  	   $sizeChild = $('lassoMask').getElement('span').getSize();
		  	  	var y = ($sizeParent.y-$sizeChild.y)/2;
		  	    if(IsIE8Browser()) y -= 15;
			  	coords.y = coords.y + y;
			    this.coords = coords;
			    var pos = {x:0,y:0}; //this.element.getPosition();
			    var form = this.getForm();
			    form.setStyles({
			      'top' : pos.y + coords.y + 20,
			      'left' : pos.x + coords.x + coords.w + 20
			    });
			}
	    });
	    
	    var taggerInstance = window.taggerInstance = new Tagger('media_photo_next', {
	      'title' : '<?php echo $this->string()->escapeJavascript($this->translate('ADD TAG'));?>',
	      'description' : '<?php echo $this->string()->escapeJavascript($this->translate('Type a tag or select a name from the list.'));?>',
	      'createRequestOptions' : {
	        'url' : '<?php echo $this->url(array('module' => 'core', 'controller' => 'tag', 'action' => 'add'), 'default', true) ?>',
	        'data' : {
	          'subject' : '<?php echo $this->subject()->getGuid() ?>'
	        }
	      },
	      'deleteRequestOptions' : {
	        'url' : '<?php echo $this->url(array('module' => 'core', 'controller' => 'tag', 'action' => 'remove'), 'default', true) ?>',
	        'data' : {
	          'subject' : '<?php echo $this->subject()->getGuid() ?>'
	        }
	      },
	      'cropOptions' : {
	        'container' : $('media_photo_next')
	      },
	      'tagListElement' : 'media_tags',
	      'existingTags' : <?php echo Zend_Json::encode($this->tags) ?>,
	      'suggestProto' : 'request.json',
	      'suggestParam' : "<?php echo $this->url(array('module' => 'user', 'controller' => 'friends', 'action' => 'suggest', 'includeSelf' => true), 'default', true) ?>",
	      'guid' : <?php echo ( $this->viewer()->getIdentity() ? "'".$this->viewer()->getGuid()."'" : 'false' ) ?>,
	      'enableCreate' : <?php echo ( $this->canTag ? 'true' : 'false') ?>,
	      'enableDelete' : <?php echo ( $this->canUntagGlobal ? 'true' : 'false') ?>
	    });
		//over function onMove
			
	    // Remove the href attrib while tagging
	    var nextHref = $('media_photo_next').get('class');
	    taggerInstance.addEvents({
	      'onBegin' : function() {
	    	  en4.ialbum.isOtherClick =  true;
//	    	  $('innerLeftCol').setStyle('line-height', 'normal');
	    	  $('innerLeftCol').scrollTo(0,0);
			  if($('boxBottomUnderImage')) $('boxBottomUnderImage').hide();
				if($$('.imageActionSwitch')) $$('.imageActionSwitch').setStyle('opacity', 0);
	      },
	      'onEnd' : function() {
//	    	  $('innerLeftCol').setStyle('line-height', ($('heightTable').get('class')/13.4).toString()+'em');
		   	  setTimeout("en4.ialbum.isOtherClick =  false", 1000);
	      }
	    });

	  
	 if($('frmEditPhoto_<?php echo $this->subject()->getType()?>_<?php echo $this->subject()->getIdentity()?>')) $('frmEditPhoto_<?php echo $this->subject()->getType()?>_<?php echo $this->subject()->getIdentity()?>').addEvent('submit', function(e){
			e.stop();
			$$('.tag_div').destroy();
			$$('.tag_label').destroy();
			var form_values  = $('frmEditPhoto_<?php echo $this->subject()->getType()?>_<?php echo $this->subject()->getIdentity()?>').toQueryString();
	        	form_values += '&format=json';
	        en4.core.request.send(new Request.JSON({
        	    url : en4.core.baseUrl + 'ialbum/photo/quick-edit',
        	    data : form_values
        	}), {
        	   	'element' : $('informations_<?php echo $this->subject()->getType()?>_<?php echo $this->subject()->getIdentity()?>')
        });	
	 });
	 $('aEdit_<?php echo $this->subject()->getType()?>_<?php echo $this->subject()->getIdentity()?>').removeClass('disableEdit');
	 $('titlePhotoValue_<?php echo $this->subject()->getType()?>_<?php echo $this->subject()->getIdentity()?>').addEvents({
		'focus': function(){
			if (this.value.contains('<?php echo $this->translate('Write a title...')?>')) this.value = '';
		},
		'blur': function(){
			if (this.value == '') this.value = '<?php echo $this->translate('Write a title...')?>';
		}
	 });
	 $('desPhotoValue_<?php echo $this->subject()->getType()?>_<?php echo $this->subject()->getIdentity()?>').addEvents({
			'focus': function(){
				if (this.value.contains('<?php echo $this->translate('Write a description...')?>')) this.value = '';
			},
			'blur': function(){
				if (this.value == '') this.value = '<?php echo $this->translate('Write a description...')?>';
			}
		 });
});
</script>
<div class="informations" id="informations_<?php echo $this->subject()->getType()?>_<?php echo $this->subject()->getIdentity()?>">
			<div id="headerBox_<?php echo $this->subject()->getType()?>_<?php echo $this->subject()->getIdentity()?>" style="display: block;">
				<div class="boxInfoUser">
					<div class="boxiconUser">
				        <?php echo $this->htmlLink($this->album->getOwner()->getHref(),$this->itemPhoto($this->album->getOwner(), 'thumb.icon')); ?>
					</div>
					<div class="boxInfoPhoto">
						<div class="boxUserLink"><?php echo $this->album->getOwner()->__toString()?></div>
						<div class="boxTimestamp"><?php echo $this->timestamp($this->photo->modified_date)?></div>
					</div>
				</div>
				
				<div style="clear: both;"></div>
				<br>
				<?php if($this->photo->getTitle()):?>
					<div class="albums_viewmedia_info_title"><?php echo $this->photo->getTitle()?></div>
				<?php endif;?>
			    <?php $isWith = false; if( $this->photo->getDescription() ): $isWith = true;?>		       
			       <span>
			        <?php echo nl2br($this->photo->getDescription()) ?>
			       </span>
			    <?php else: $isWith = false;?>
			     <?php if( $this->canEdit ): ?>
				    <div>				    	
				    	<a href="javascript: void(0);" onclick="editPhoto(this, true);$('desPhotoValue_<?php echo $this->subject()->getType()?>_<?php echo $this->subject()->getIdentity()?>').focus();"><?php echo $this->translate('Add a description');?></a>
				    </div>
				    
			    <?php endif;?>
			    <?php endif; ?>
				<span class="albums_viewmedia_info_tags" id="media_tags" style="display: none;">
	      			<?php echo ($isWith)?'&nbsp;&ndash;&nbsp;'. $this->translate('with ') : $this->translate('With ');?>
	    		</span>
	    	</div>
	    	<?php if($this->canEdit):?>
	    	<form id="frmEditPhoto_<?php echo $this->subject()->getType()?>_<?php echo $this->subject()->getIdentity()?>" name="frmEditPhoto" method="post" enctype="application/x-www-form-urlencoded">
		    	<div id="boxEdit_<?php echo $this->subject()->getType()?>_<?php echo $this->subject()->getIdentity()?>" class="boxEdit" style="display: none;">
		    		<div class="photoTitle gen">
		    			<input class="titlePhotoValue" id="titlePhotoValue_<?php echo $this->subject()->getType()?>_<?php echo $this->subject()->getIdentity()?>" class="textInput" type="text" name="title" value="<?php echo ($this->photo->getTitle())? $this->photo->getTitle() : $this->translate('Write a title...');?>">
		    		</div>
		    		<div class="photoDes gen">
		    			<textarea id="desPhotoValue_<?php echo $this->subject()->getType()?>_<?php echo $this->subject()->getIdentity()?>" name="description" id="photoDesArea_<?php echo $this->subject()->getType()?>_<?php echo $this->subject()->getIdentity()?>" class="areaDes"><?php echo ($this->photo->getDescription()) ? $this->photo->getDescription() : $this->translate('Write a description...')?></textarea>
		    		</div>
		    		<input type="hidden" value="<?php echo $this->album->getIdentity()?>" name="album_id">
		    		<input type="hidden" value="<?php echo $this->photo->getIdentity()?>" name="photo_id">
					<div class="editActions">
						<button type="submit" name="submit" ><?php echo $this->translate('Save changes');?></button>
						<button type="button" name="cancel" onclick="editPhoto(this, false);"><?php echo $this->translate('Cancel');?></button>
					</div>		    	
		    	</div>
		    </form>
	    	<?php endif;?>
	    </div>